﻿using JetBrains.Annotations;
using System;
using System.Diagnostics;
using System.Reflection;

namespace Xms.Abp.Authorization;

[AttributeUsage(AttributeTargets.Class)]
public class DynamicPermissionsUseAttribute: PermissionsUseAttribute
{
    public DynamicPermissionsUseAttribute(
            [NotNull] Type sourceType,
            [CanBeNull] string permissionsConstTypePropertyName)
    {
        var permissionsConstTypeProperty = sourceType.GetProperty(
            permissionsConstTypePropertyName,
            BindingFlags.Static | BindingFlags.Public
        );
        Debug.Assert(permissionsConstTypeProperty != null, nameof(permissionsConstTypeProperty) + " != null");
        PermissionsConstType = (Type)permissionsConstTypeProperty.GetValue(null);
    }
}
